package com.szgr.baoyin.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;

import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.adapter.ChooseCityListAdapter;
import com.szgr.baoyin.model.City;
import com.szgr.baoyin.myview.indexbar.IndexableListView;

/**
 * 选择城市
 */
public class ChooseCityActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    private EditText et_search;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_choose_city);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initActionBar() {
        actionBarTitle.setText("选择城市");
    }

    @Override
    public void initView() {
        IndexableListView cityListView = (IndexableListView) findViewById(R.id.choose_city_list_view);
        cityListView.setAdapter(new ChooseCityListAdapter(this, MyApplication.getAllCity()));
        cityListView.setFastScrollEnabled(true);
        cityListView.setOnItemClickListener(this);
        et_search = (EditText) findViewById(R.id.et_search);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.action_bar_left:
                finish();
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if(parent.getAdapter().getItemViewType(position) == ChooseCityListAdapter.TYPE_ITEM){
            City city = (City) parent.getAdapter().getItem(position);
            et_search.setText(city.getName());
        }
    }
}
